package com.ruoyi.hr.controller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.hr.domain.HrOperateLog;
import com.ruoyi.hr.service.IHrOperateLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@RestController
@RequestMapping("/hr/operation")
public class HrOperationLogController {

	@Autowired
	private IHrOperateLogService hrOperateLogService;
	/**
	 * 简单查询出指定简历的所有的操作日志
	 */
	@GetMapping("/{id}")
	public AjaxResult queryLogsByResumeId(@PathVariable("id") Long resumeId){
		HrOperateLog hrOperateLog = new HrOperateLog();
		hrOperateLog.setResumeId(resumeId);
		List<HrOperateLog> hrOperateLogs = hrOperateLogService.selectHrOperateLogList(hrOperateLog);
		Collections.sort(hrOperateLogs, (o1, o2) -> {
			// 假设getTime()返回的是Date类型，我们使用Date的compareTo方法进行比较
			// 注意：compareTo方法默认是升序的，所以为了得到降序，我们需要交换o1和o2的位置
			return o2.getTime().compareTo(o1.getTime());
		});
		return AjaxResult.success().put("data", hrOperateLogs);
	}
}
